package com.slipper.sfts.broker.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;

import com.slipper.sfts.broker.dao.BrokerAccountDao;
import com.slipper.sfts.api.broker.bo.BrokerAccountBO;

import com.slipper.common.transaction.ReadTransactional;
import com.slipper.common.transaction.WriteTransactional;
import com.slipper.common.util.Tool;

@Service
@ReadTransactional
public class BrokerAccountService {
    @Resource
    private BrokerAccountDao brokerAccountDao;
    
    public BrokerAccountBO queryBy(String id) {
        return brokerAccountDao.queryBy(id);
    }
    
    public List<BrokerAccountBO> queryList(BrokerAccountBO bo) {
        return brokerAccountDao.queryList(bo);
    }
    
    public PageInfo<BrokerAccountBO> queryPage(BrokerAccountBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(brokerAccountDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(BrokerAccountBO bo) {
        if (bo.getId() != null && !"".equals(bo.getId())) {
            return brokerAccountDao.update(bo);
        } else {
            bo.setId(Tool.getUUID());
            return brokerAccountDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(BrokerAccountBO bo) {
        return brokerAccountDao.delete(bo);
    }
}
